
//
//  UserModel.m
//  LiveStar
//
//  Created by SKT1 on 2016/12/5.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "UserModel.h"
#import <objc/runtime.h>

@implementation UserModel


//编码
- (void)encodeWithCoder:(NSCoder *)aCoder {
    [aCoder encodeObject:self.u_nickname forKey:@"u_nickname"];
    [aCoder encodeObject:self.u_avatar forKey:@"u_avatar"];
    [aCoder encodeObject:self.u_sex forKey:@"u_sex"];
    [aCoder encodeObject:self.u_type forKey:@"u_type"];
    [aCoder encodeObject:self.udid forKey:@"udid"];
    [aCoder encodeObject:self.u_balance forKey:@"u_balance"];
    [aCoder encodeObject:self.tim forKey:@"tim"];
    [aCoder encodeObject:self.level forKey:@"level"];
    [aCoder encodeObject:self.u_source forKey:@"u_source"];
    [aCoder encodeObject:self.u_city forKey:@"u_city"];
    [aCoder encodeObject:self.u_province forKey:@"u_province"];
    [aCoder encodeObject:self.u_age forKey:@"u_age"];
    [aCoder encodeObject:self.u_region forKey:@"u_region"];
    
}
//解码
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    if (self = [super init]) {
        self.u_nickname = [aDecoder decodeObjectForKey:@"u_nickname"];
        self.u_avatar = [aDecoder decodeObjectForKey:@"u_avatar"];
        self.u_sex = [aDecoder decodeObjectForKey:@"u_sex"];
        self.u_type = [aDecoder decodeObjectForKey:@"u_type"];
        self.udid = [aDecoder decodeObjectForKey:@"udid"];
        self.u_balance = [aDecoder decodeObjectForKey:@"u_balance"];
        self.tim = [aDecoder decodeObjectForKey:@"tim"];
        self.level = [aDecoder decodeObjectForKey:@"level"];
        self.u_source = [aDecoder decodeObjectForKey:@"u_source"];
        self.u_city = [aDecoder decodeObjectForKey:@"u_city"];
        self.u_province = [aDecoder decodeObjectForKey:@"u_province"];
        self.u_age = [aDecoder decodeObjectForKey:@"u_age"];
        self.u_region = [aDecoder decodeObjectForKey:@"u_region"];
    }
    return self;
}

- (NSString *)debugDescription
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    unsigned int count;
    objc_property_t *properties = class_copyPropertyList([self class], &count);
    for (int i = 0; i < count; i++) {
        objc_property_t property = properties[i];
        NSString *properName = @(property_getName(property));
        id value = [self valueForKey:properName] ?: @"nil"; //默认值为 nil 字符串
        [mutableDict setObject:value forKey:properName]; //装载到字典里
    }
    free(properties);
    
    return [NSString stringWithFormat:@"<%@: %p> -- %@", [self class], self, mutableDict];
}

@end
